import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * DefaultLayoutAction
 *
 * 通用的 一般情况下的 Layout 的 初始化流程
 *
 * @date 2019/8/27
 */
import React, { Component } from 'react';
import { connect } from 'dva';
import dynamic from 'dva/dynamic';
import LoadingBar from "../../../components/NProgress/LoadingBar";
import { tabListen } from "../../../utils/menuTab";

var DefaultLayoutAction = /*#__PURE__*/function (_Component) {
  _inherits(DefaultLayoutAction, _Component);

  var _super = _createSuper(DefaultLayoutAction);

  function DefaultLayoutAction() {
    _classCallCheck(this, DefaultLayoutAction);

    return _super.apply(this, arguments);
  }

  _createClass(DefaultLayoutAction, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      // 清除首屏loading
      var loader = document.querySelector('#loader-wrapper');

      if (loader) {
        document.body.removeChild(loader); // 设置默认页面加载动画

        dynamic.setDefaultLoadingComponent(function () {
          return /*#__PURE__*/React.createElement(LoadingBar, null);
        });
      }

      this.init();
    }
  }, {
    key: "init",
    value: function init() {
      var _this$props = this.props,
          dispatch = _this$props.dispatch,
          _this$props$currentUs = _this$props.currentUser,
          currentUser = _this$props$currentUs === void 0 ? {} : _this$props$currentUs;
      var language = currentUser.language;
      dispatch({
        type: 'global/baseLazyInit',
        payload: {
          language: language
        }
      }).then(function () {
        // 初始化菜单成功后 调用 tabListen 来触发手动输入的网址
        tabListen();
        dispatch({
          type: 'global/initActiveTabMenuId'
        });
      });
    }
  }, {
    key: "render",
    value: function render() {
      return null;
    }
  }]);

  return DefaultLayoutAction;
}(Component);

export default connect(function (_ref) {
  var _ref$user = _ref.user,
      user = _ref$user === void 0 ? {} : _ref$user;
  return {
    currentUser: user.currentUser // 当前用户

  };
}, null, null, {
  pure: false
})(DefaultLayoutAction);